﻿$(function(){//延迟加载
	var datares=null;
	var url='';
	var danxuan='';
	var flag='0';
	
	$("#availpon",parent.document).click(function(){
		url='shownewsvgmap?danxuan=0&dvtable=oltinfo&stype=1&reqfield=oltuseponnum';
		recreatmap(url);
//		$.ajax({
//			url:'showjxpon',
//			success:function(data){
//				$('#MapControl .list1').empty();
//				datares = {
//						"fangzhicheng":{"value":"30.05%","index":"1","stateInitColor":"0"}
//						};
//				alert(data.fangzhicheng.value);
//				datares =data;
//				creatmap(datares);
//			}
//		});
	});
	$("#oltres",parent.document).click(function(){
		url='shownewsvgmap?danxuan=0&dvtable=oltinfo&stype=0&reqfield=0';
		recreatmap(url);
		$("#searcholtmap",parent.document).click(function(){
			var oltpontype=$("#oltpontype",parent.document).val();
			var olttype=$("#olttype",parent.document).val();
			alert(olttype);
			danxuan='';
			flag='0'
			if(oltpontype!='0'){
				danxuan='oltpontype,'+oltpontype+":";
				flag='1';
			}
			if(olttype!='0'){
				danxuan=danxuan+'olttype,'+olttype+":";
				flag='1';
			}
			if(flag=='0'){
				danxuan='0';
			}else	
				danxuan = danxuan.substring(0,danxuan.length-1);
			url='shownewsvgmap?danxuan='+danxuan+'&dvtable=oltinfo&stype=0&reqfield=0';
			recreatmap(url);
		});
	});
	
	function recreatmap(url){
		$.ajax({
			url:url,
			success:function(data){
				$('#MapControl .list1').empty();
				datares =data;
				creatmap(datares);
			}
		});
	}
	
	function creatmap(datares){
		var i = 1;
		var ct=0;
		for(k1 in datares){
			var _cls = i < 4 ? 'active' : ''; 
			$('#MapControl .list1').append('<li name="'+k1+'"><div style="width:300px" class="mapInfo"><i class="'+_cls+'">'+(i++)+'</i><span>'+chinaMapConfig.names[k1]+datares[k1].value+'</span></div></li>')
		}

		var mapObj_1 = {};
		var stateColorList = ['003399', '0058B0', '0071E1', '1C8DFF', '51A8FF', '82C0FF', 'AAD5ee', 'AAD5FF'];
		
		$('#RegionMap').SVGMap({
			external: mapObj_1,
			mapName: 'china',
			mapWidth: 600,
			mapHeight: 500,
			stateData: datares,
			clickCallback: function(mapData, obj){
				parent.addTab(mapData[obj.id].jxname,'creatjxmap?jxId='+mapData[obj.id].jxId+'&dvbelong=switch');
		    },
			stateTipHtml: function (mapData, obj) {
				var _value = mapData[obj.id].value;
				var _idx = mapData[obj.id].index;
				var active = '';
				_idx < 4 ? active = 'active' : active = '';
				var tipStr = '<div  class="mapInfo"><i class="' + active + '">' + _idx + '</i><span>' + obj.name + '</span><b>' + _value + '</b></div>';
				return tipStr;
			}
		});
		$('#MapControl li').hover(function () {
			var thisName = $(this).attr('name');
			
			var thisHtml = $(this).html();
			$('#MapControl li').removeClass('select');
			$(this).addClass('select');
			$(document.body).append('<div id="StateTip"></div');
			$('#StateTip').css({
				left: $(mapObj_1[thisName].node).offset().left - 50,
				top: $(mapObj_1[thisName].node).offset().top - 40
			}).html(thisHtml).show();
			mapObj_1[thisName].attr({
				fill: '#E99A4D'
			});
		}, function () {
			var thisName = $(this).attr('name');

			$('#StateTip').remove();
			$('#MapControl li').removeClass('select');
			mapObj_1[$(this).attr('name')].attr({
				fill: "#" + stateColorList[datares[$(this).attr('name')].stateInitColor]
			});
		});
		$('#MapControl li').click(function(){
			alert($(this).attr('name'));
			alert('OK');
		});
		
		$('#MapColor').show();		
	}
			
});